package 链表.删除链表的节点;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2023/3/14 17:08
 * @description:
 * @version:
 */
public class Solution {
    public static void main(String[] args) {
        ListNode node = new ListNode(4,new ListNode(5,new ListNode(1,new ListNode(9))));
        ListNode listNode = deleteNode(node, 1);
        System.out.println(listNode.val);
    }

    public static ListNode deleteNode(ListNode head, int val) {
        ListNode root = new ListNode(0);
        root.next = head;
        ListNode pre = root;
        ListNode p = root.next;
        while (p != null){
            if (p.val == val){
                pre.next = p.next;
            }
            pre = pre.next;
            p = p.next;
        }
        return root.next;
    }

}
